package modeleditor.editor;

import java.awt.Container;
import java.awt.Dimension;

import javax.swing.JPanel;

import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
import org.jfree.chart.plot.SpiderWebPlot;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RectangleEdge;
import org.jfree.ui.RefineryUtilities;

import spiderwebchart.Spiderwebchart;

/**
 * A simple demonstration application showing how to create a spider chart.
 */
public class drawspiderwebchart {

	private static Spiderwebchart spiderwebchart;
	
    public drawspiderwebchart(Spiderwebchart spiderwebchart) {
    	this.spiderwebchart = spiderwebchart;
        //JPanel chartPanel = createDemoPanel();
        //chartPanel.setPreferredSize(new Dimension(500, 270));

    }

    /**
     * Returns a sample dataset.
     * 
     * @return The dataset.
     */
    public static CategoryDataset createDataset() {
        // create the dataset...
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    	for(int i=0; i<spiderwebchart.getSubcharts().size(); i++){
        	for(int j=0; j<spiderwebchart.getSubcharts().get(i).getPoints().size(); j++){
        		dataset.addValue(spiderwebchart.getSubcharts().get(i).getPoints().get(j).getValue(),
        				spiderwebchart.getSubcharts().get(i).getName(), spiderwebchart.getSubcharts().get(i).getPoints().get(j).getAttributeName());
        	}
        }
        
        return dataset;
        
    }
    
    /**
     * Creates a sample chart.
     * 
     * @param dataset  the dataset.
     * 
     * @return The chart.
     */
    public static JFreeChart createChart(CategoryDataset dataset) {
        SpiderWebPlot plot = new SpiderWebPlot(dataset);
        plot.setStartAngle(54);
        plot.setInteriorGap(0.40);
        plot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
        JFreeChart chart = new JFreeChart(spiderwebchart.getChartname(), 
                TextTitle.DEFAULT_FONT, plot, false);
        LegendTitle legend = new LegendTitle(plot);
        legend.setPosition(RectangleEdge.BOTTOM);
        chart.addSubtitle(legend);   
        return chart;
        
    }
    
    /**
     * Creates a panel for the demo (used by SuperDemo.java).
     * 
     * @return A panel.
     */
    public static JPanel createDemoPanel() {
        JFreeChart chart = createChart(createDataset());
        return new ChartPanel(chart);
    }

}

